package com.xjh.mange.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xjh.mange.common.enums.DeleteStatusEnum;
import com.xjh.mange.mapper.PasswordMapper;
import com.xjh.mange.model.Password;
import com.xjh.mange.service.PasswordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 徐佳辉
 * @date 2020/12/20 15:28
 */
@Service
public class PasswordServiceImpl extends ServiceImpl<PasswordMapper, Password> implements PasswordService {

    @Autowired
    private PasswordMapper passwordMapper;

    @Override
    public IPage<Password> listOrName(int page, int limit, String name) {
        IPage<Password> passwordIPage = new Page<>(page, limit);
        QueryWrapper<Password> wrapper = new QueryWrapper<>();
        wrapper.eq("del", DeleteStatusEnum.NOT_DELETE.getCode());
        wrapper.orderByDesc("create_time");
        if (StringUtils.isBlank(name)) {
            return passwordMapper.selectPage(passwordIPage, wrapper);
        } else {
            wrapper.like("name", name).or().like("count_name", name);
            return passwordMapper.selectPage(passwordIPage, wrapper);
        }

    }
}
